<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>react 受控组件</title>
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="">
</head>

<body>

    <div id="react"> </div>
    <!--准备好一个容器-->
    <div id="test"></div>
    <!--引入react核心库,核心库必须先引入-->
    <script type="text/javascript" src="./js/react.development.js"></script>
    <!--引入react-dom, 用于支持react操作DOM-->
    <script type="text/javascript" src="./js/react-dom.development.js"></script>
    <!--引入babel,用于将jsx转为js-->
    <script type="text/javascript" src="./js/babel.min.js"></script>

    <!-- 引入prop-types，用于对组件标签属性进行限制 -->
    <script type="text/javascript" src="./js/prop-types.js"></script>

   <div id="react"></div>

      
    <script type="text/babel">

    //非受控组件：先用先取
    class Login extends React.Component {

     getSubmit=()=>{

     //阻止默认事件
     event.preventDefault()
     
     alert(`用户名：${this.ipt.value},密码：${this.iptT.value}`)
     }

      render() {
         return (
           <form action="https://developer.mozilla.org/" onSubmit={this.getSubmit}>
            姓名:<input ref={(a)=>{this.ipt=a}} type="text" name="username"/>
            密码:<input ref={(b)=>{this.iptT=b}} type="password" name="password"/>
            <button>登录</button>
           </form>
         )
      }

    }

   ReactDOM.render(<Login/>,document.getElementById("react"))
  



    </script>
    <style>
        .spacing {
            margin: 15px;
        }
    </style>

</body>

</html>